var popupTempHtml = "<h4>{0}</h4><div id=\"wrapper\" style=\"position:relative; height:100%;\"><div id=\"scroller\">{1}</div></div><span class=\"lp_close\"><a href=\"javascript:fncPopupClose()\">닫기</a></span>";
var imageViewHtml = "<div class=\"p_imgpop\"><div id=\"wrapper\"><div class=\"p_imgArea\">{0}</div></div><p class=\"bx_close\"><a href=\"javascript:fncPopupClose()\"><img src=\"/m/images/button/btn_pop_img_close.gif\" alt=\"닫기\"></a></p></div>";
fontSizes = new Array('18px', '20px', '22px');
fontResizeTarget="nahfContent";


/**
 * 해제뷰어
 * @param levelId
 * @param srcXml
 * @param title
 * @param name
 * @param type
 */

function goFront(levelId, srcXml, title, name, type) {
	$.startProcessing();
	window.scrollTo(0,0);
	if(!type)type = title;
	$.getJSON( "/m/directory/itemFront.do", { levelId: levelId, srcXml: srcXml,  title:title, name:name, type:type}, function( data ) {
		
		var popupHtml = popupTempHtml.replace("{0}", data.title);
		popupHtml = popupHtml.replace("{1}", data.biblioHtml+"<div  style='height:50px'></div>");
		$("#nahfWrap").hide();
		$.stopProcessing();
		$(".Layerpop").html(popupHtml);
		$(".Layerpop").show();
		
		new iScroll('wrapper');
	});
}

function goMapViewer(levelId, x, y) {
	$.processing();
	document.viewerForm.levelId.value = levelId;
	document.viewerForm.x.value = x;
	document.viewerForm.y.value = y;
	document.viewerForm.action = '/m/imageViewer/mapViewer.do';
	document.viewerForm.submit();
}

function goImageViewer(levelId) {
	$.processing();
	document.viewerForm.levelId.value = levelId;
	document.viewerForm.action = '/m/imageViewer/imageViewer.do';
	document.viewerForm.submit();
	
	/*
	$.startProcessing();
	window.scrollTo(0,0);
	$.getJSON('/m/imageViewer/retrieveViewerImage.do?levelId='+levelId, function(data) {
		
		var itemFileList = data.itemFileResultList.list;
		if(itemFileList.length > 0){
			var thumbnail = "";
			for(var i = 0; i < itemFileList.length; i++){
				thumbnail += "<p><img src=\"http://contents.nahf.or.kr/"+itemFileList[i].basePath + itemFileList[i].filePath + itemFileList[i].fileName+"\" alt=\"\" height=\""+($(window).height())+"\"/></p>";
			}
			$.stopProcessing();
			var popupHtml = imageViewHtml.replace("{0}", thumbnail);
			var height = window.outerHeight ? window.outerHeight : $(window).height();
			$(".Layerpop").height(height);
			$(".Layerpop").html(popupHtml);
			$(".Layerpop").show();
			
			$("#wrapper").touchSlider({
				flexible : true,
				counter : function (e) {
					
				}
			});
			
		}
	});
	*/
	
}

function goBookViewer(levelId) {
	$.processing();
	document.viewerForm.levelId.value = levelId;
	document.viewerForm.action = '/m/imageViewer/bookViewer.do';
	document.viewerForm.submit();
	
	/*
	imageArray = new Array();
	imageCount = -1;
	currentCount = 0;
	imageDivCnt = 3;
	$.startProcessing();
	window.scrollTo(0,0);
	$.getJSON('/m/imageViewer/bookViewer.do?levelId='+levelId, function(data) {
		
		var itemFileList = data.imageList;
		if(itemFileList.length > 0){
			var thumbnail = "";
			
			thumbnail += "<p><img id='bookImg0' src='' alt=\"\" height=\""+($(window).height()-20)+"\"/></p>";
			imageArray.push("http://contents.nahf.or.kr/"+itemFileList[0]);
			if(itemFileList.length > 1) {
				thumbnail += "<p><img id='bookImg1' src='' alt=\"\" height=\""+($(window).height()-20)+"\"/></p>";
				thumbnail += "<p><img id='bookImg2' src='' alt=\"\" height=\""+($(window).height()-20)+"\"/></p>";
			}
			for(var i = 1; i < itemFileList.length; i++) {
				imageArray.push("http://contents.nahf.or.kr/"+itemFileList[i]);
			}
			
			$.stopProcessing();
			var popupHtml = imageViewHtml.replace("{0}", thumbnail);
			var height = window.outerHeight ? window.outerHeight : $(window).height();
			$(".Layerpop").height(height);
			$(".Layerpop").html(popupHtml);
			$(".Layerpop").show();
			
			imageSlider = $("#wrapper").touchSlider({
				flexible : true,
				counter : function (e) {
					
					var count = e.current;
					
					if(currentCount == imageDivCnt) {
						if(count == 1) {
							imageCount++;
							//console.log("a"+imageCount);
						} else {
							imageCount--;
							//console.log("b"+imageCount);
						}
					} else if(currentCount == 1) {
						if(count == imageDivCnt) {
							imageCount--;
							//console.log("c"+imageCount);
						} else {
							imageCount++;
							//console.log("d"+imageCount);
						}
					} else {
						if(currentCount < count) {
							imageCount++;
							//console.log("e"+imageCount);
						} else {
							imageCount--;
							//console.log("f"+imageCount);
						}
					}
					if(imageCount < 0) {
						imageCount = imageArray.length - 1;
					}
					if(imageCount > imageArray.length - 1) {
						imageCount = 0;
					}
					currentCount = count;
					$('#bookImg0').attr({src:''});
					$('#bookImg1').attr({src:''});
					$('#bookImg2').attr({src:''});
					$('#bookImg'+(count-1)).attr({src:imageArray[imageCount], titie:imageCount});
					
				}
			});
			
		}
	});
	*/
}


/**
 * 색인어조회
 * @param levelId
 * @param srcXml
 * @param title
 * @param name
 * @param type
 */

function goIndexList(levelId, indexWord, indexId, type) {
	$.startProcessing();
	window.scrollTo(0,0);
	if(!type)type = title;
	$.getJSON( "/m/index/retrieveIndex.do", { levelId: levelId, 'indexInfo.indexWord':indexWord, indexId:indexId, type:type}, function( data ) {
		
		var popupHtml = popupTempHtml.replace("{0}", "색인어정보");
		
		var relInfoHtml = "<table class=\"tbl_list_nor bg_gray\"><caption>관련 목록 정보</caption><colgroup><col width=\"25%\"/><col width=\"75%\"/></colgroup><tr><td>색인어</td><td class=\"b\">"+data.indexInfo.indexWord+"</td></tr><tr><td>유형</td><td class=\"b\">"+data.indexInfo.types+"</td></tr>";
		
		var relInfo = "";
		if(data.indexInfo.uci != "" && data.indexInfo.uci != null){
			relInfo += "<a href='http://uci.or.kr/"+data.indexInfo.uci+"' target='_blank'>UCI</a>";
		} 
		if (data.indexInfo.url != "" && data.indexInfo.url != null) {
			relInfo += "<a href='"+data.indexInfo.url+"' target='_blank'>UCI</a>";
		} 
		if (data.indexInfo.gis != "" && data.indexInfo.gis != null) {
			relInfo += "GIS:"+data.indexInfo.gis;
		} 
		
		if(relInfo == "") {
			relInfo = "없음";
		}
		
		relInfoHtml += "<tr><td>연관정보</td><td class=\"b\">"+relInfo+"</td></tr></table>";
		
		var relList = "<table class=\"tbl_list_nor\"><caption>관련 목록</caption><colgroup><col width=\"45%\"/><col width=\"55%\"/></colgroup>";
		for(var i = 0; i < data.listResult.list.length; i++) {
			var indexLevel = data.listResult.list[i];
			relList += "<tr><td>"+indexLevel.itemLevel.levelId+"</td><td>"+indexLevel.itemLevel.mainTitle+"</td></tr>";
		}
		relList += "</table>";
		popupHtml = popupHtml.replace("{1}", relInfoHtml+relList+"<div  style='height:50px'></div>");
		$("#nahfWrap").hide();
		$.stopProcessing();
		$(".Layerpop").html(popupHtml);
		$(".Layerpop").show();
		
		new iScroll('wrapper');
	});
}

function goDown(fileUrl) {
	showAlertWorking();
}

//번역보기
function showOrigin(){
	//탭네비 스타일 변경
	//$('#liOrigin').show();
	$('#liMark').removeClass("active");
	$('#liTrans').removeClass("active");
	$('#liCompare').removeClass("active");
	$('#liTrans').removeClass("active");
	
	$('#liOrigin').addClass("active");
	
	//탭 영역 이벤트처리
	
	$('#itemMark').hide();
	$('#itemTrans').hide();
	$('#itemOrigin').show();
}

//번역보기
function showTrans(){
	//탭네비 스타일 변경
	//$('#liOrigin').show();
	$('#liMark').removeClass("active");
	$('#liTrans').removeClass("active");
	$('#liCompare').removeClass("active");
	$('#liOrigin').removeClass("active");
	
	$('#liTrans').addClass("active");
	
	//탭 영역 이벤트처리
	$('#itemOrigin').hide();
	$('#itemMark').hide();
	$('#itemTrans').show();
}
//표점보기
function showMark(){
	//탭네비 스타일 변경
	//$('#liOrigin').show();
	$('#liMark').removeClass("active");
	$('#liTrans').removeClass("active");
	$('#liCompare').removeClass("active");
	$('#liOrigin').removeClass("active");
	
	$('#liMark').addClass("active");
	
	//탭 영역 이벤트처리
	$('#itemOrigin').hide();
	$('#itemTrans').hide();
	$('#itemMark').show();
	
}

function fncSelectMenu(type, typeCd) {
	window.location.href = "/m/directory/all.do?itemType="+type+"&"+type+"Cd="+typeCd;
}

function fncPage(pageIndex) {
	$.processing();
	document.searchVO.page.value = pageIndex;
	document.searchVO.submit();
}

function goMap(latitude, longitude, title) {
	if(title)title=encodeURI(title);
	if(latitude)latitude = $.trim(latitude);
	if(longitude)longitude = $.trim(longitude);
	  window.location.href='/m/directory/map.do?levelId='+$("#levelId").val()+'&latitude='+latitude+'&longitude='+longitude+'&title='+title, '인쇄', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,top=100,left=250,width=800,height=600';
}
